{extend name="public/base" /}
{block name="title"}退货订单管理{/block}
{block name="content"}
<div class="layui-fluid">   
  <div class="layui-card">
    <form class="layui-form layui-card-header layuiadmin-card-header-auto" id="searchForm">
      <div class="layui-form-item asuma-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">订单编号</label>
            <div class="layui-input-block">
                <input type="text" name="order_no" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">订单状态</label>
          <div class="layui-input-block">
              <select name="order_status">
                <option value="">请选择状态</option>
                <option value="5">退款中</option>
                <option value="6">已退款</option>
                <option value="11">申请退款(未发货时)</option>
                <option value="31">申请退货退款(已完成时)</option>
              </select>
          </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-asuma layuiadmin-btn-admin" lay-submit lay-filter="orderSearch">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>
      </div>
    </form>
    
    <div class="layui-card-body">
       
        <table id="order" lay-filter="order"></table>  
    </div>
  </div>
</div>
{/block}
{block name="footjs"}
<script type="text/html" id="optTpl">
  <a class="layui-btn layui-btn-asuma layui-btn-xs" lay-event="detail">详情</a>
  {{# if(d.order_status == 11){ }}
  <a class="layui-btn layui-btn-asuma layui-btn-xs" lay-event="change">审核退款</a>
  {{# } }}
</script>

<script>
  layui.config({
    base: '__JS__/layuiext/' //静态资源所在路径
  }).use([ 'table','form','upload'], function(){
    var $ = layui.$
    ,form = layui.form
    ,table = layui.table
    ,upload = layui.upload;


   var tableIns =  table.render({
      elem: '#order'
      ,url: "{:route('Order/returnOrderList')}" //数据接口
      ,page: true //开启分页
      ,limit:10
      ,limits:[10,25,50]
      ,defaultToolbar: ['filter', 'print']
      ,done:function (res, curr, count) {
        if(count <= this.limit){
          $('.layui-table-page').addClass('layui-hide');//总条数小于每页限制条数时隐藏分页
        }
      }
      ,cols: [[ //表头
        {field: 'return_order_no', title: '退货订单号', width: 210}
        ,{field: 'order_no', title: '订单编号', width: 180}
        ,{field: 'pay_time', title: '支付时间', width: 180, sort: true}
        ,{field: 'create_time', title: '退款申请时间', width: 180, sort: true}
        ,{field: 'price', title: '订单价格'} 
        ,{field: 'pay_money', title: '实际支付'} 
        ,{field: 'pay_type', title: '支付类型',templet:function(d){
          var pay_type='';
          if(d.order_status != 0 && d.order_status !=4){
            switch(d.pay_type){
              case 1:  pay_type = '微信支付'; break;
              case 2:  pay_type = '支付宝'; break;
              case 3:  pay_type = '积分'; break;
              default: pay_type = '其他';break;
            }
          }
          return pay_type;
        }} 
        ,{field: 'nickname', title: '用户名'}
          ,{field: 'order_status', title: '订单状态', templet: function(d){
          var order_status = ''
          switch(d.order_status){
            case 5:  order_status = '退款中'; break;
            case 6:  order_status = '已退款'; break;
            case 11:  order_status = '申请退款(未发货)'; break;
            case 31:  order_status = '申请退货退款(已发货)'; break;
            default:;break;
          }
          return order_status;
        }}
        ,{title: '操作',toolbar: '#optTpl', width: 150}
      ]]
    });
   
    table.on('sort(order)',function(obj){
      if(tableIns.config.page.count <= tableIns.config.page.limit){
        $('.layui-table-page').addClass('layui-hide');//总条数小于每页限制条数时隐藏分页
      }
    })

    //监听搜索
    form.on('submit(orderSearch)', function(data){
      let field = data.field;
      //执行重载
      tableIns.reload({
        where: field
        ,page:{curr:1}
      });

      return false;
    });

    table.on('tool(order)', function(obj){
        switch(obj.event){
          case 'detail':
              layer.open({
                type: 2
                ,title: obj.data.order_no
                ,content: "{:route('detail')}?order_no="+obj.data.order_no
                ,maxmin: true
                ,area: ['80%', '90%']
                ,success: function (layero, index) {
                   layero.find('input[name=id]').val(obj.data.id)
                }
              });
          break;
          case 'change':
              layer.confirm('确认退款？', function(index){
                    var load = layer.msg('正在查询退款状态', {icon: 16, shade: 0.01, time:0});
                    $.post("{:route('Order/backMoney')}", {order_no:obj.data.order_no}, function(res){
                      if(res.code == 1){
                        layer.msg('审核成功');
                        table.reload('order'); //重载表格
                        layer.close(load);
                        layer.close(index);
                      }else{
                        layer.msg(res.result, {icon: 5});
                      }
                    },'json');

                }); 
          break;
        };
    });


  });
</script>
{/block}